import cv2 as cv 

cap = cv.VideoCapture(0)
if not cap.isOpened():
    print('viddeo is not  open')
    exit()

while True:
    ret,frame=cap.read()
    if not ret :
        print('error')
        break
    gary = cv.cvtColor(frame,cv.COLOR_BGR2GRAY)
    cv.imshow ('frame',gary)
    if cv.waitKey(1)== ord('q'):
        break

cap.release()
cv.destroyAllWindows()
